/*
 * Copyright (c) 2016 zhangcm. All Rights Reserved.
 */
package com.jnzc.ocr.rest.app.shop.controller.app;

import com.jnzc.ocr.common.bean.Page;
import com.jnzc.ocr.common.bean.PageResult;
import com.jnzc.ocr.common.vo.UserVo;
import com.jnzc.ocr.dependencies.rest.base.BaseController;
import com.jnzc.ocr.serv.shop.api.ShopNoticeApi;
import com.jnzc.ocr.serv.shop.api.ShopNoticeApi;
import com.jnzc.ocr.serv.shop.entity.ShopNotice;
import com.jnzc.ocr.serv.shop.entity.ShopNotice;
import com.jnzc.ocr.serv.shop.filter.ShopNoticeFilter;
import com.jnzc.ocr.serv.shop.filter.ShopNoticeFilter;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhangcm
 * @version 1.0, 2017/9/13
 */
@Api(tags = {"app - 通知接口"})
@RestController
@RequestMapping("/app/notices")
public class AppNoticeController extends BaseController {

    @Autowired
    private ShopNoticeApi shopNoticeApi;

    @ApiOperation(value = "分页")
    @GetMapping("")
    public PageResult<ShopNotice> search(Page page){
        UserVo userVo = super.get();
        ShopNoticeFilter noticeFilter = new ShopNoticeFilter();
        noticeFilter.setShopId(userVo.getShopId());
        noticeFilter.setOrderBy("createTime desc, id desc");
        return shopNoticeApi.search(noticeFilter, page.getPageNo(), page.getPageSize());
    }

    @ApiOperation(value = "详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "通知ID", required = true, paramType = "path")
    })
    @GetMapping("/{id}")
    public ShopNotice info(@PathVariable Long id){
        UserVo userVo = super.get();
        return shopNoticeApi.find(id, userVo.getShopId());
    }
}
